package com.xbongbong.admin.service.impl;

import com.xbongbong.admin.domain.entity.VideoEntity;
import com.xbongbong.admin.model.VideoModel;
import com.xbongbong.admin.pojo.VideoPojo;
import com.xbongbong.admin.pojo.dto.TemplateVideoListDTO;
import com.xbongbong.admin.pojo.vo.TemplateVideoListVO;
import com.xbongbong.admin.service.VideoService;
import com.xbongbong.paas.enums.DelEnum;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.paas.toolbox.util.BeanUtil;
import com.xbongbong.pro.constant.RaidersConstant;
import com.xbongbong.pro.enums.errorcodes.SystemErrorCodeEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 视频
 *
 * @author 徐俊杰
 * @version v1.0
 * @date 2019/9/25 19:40
 * @since v1.0
 */
@Service("videoService")
public class VideoServiceImpl implements VideoService {
    private static final Logger LOG = LoggerFactory.getLogger(VideoServiceImpl.class);

    @Resource
    private VideoModel videoModel;

    @Override
    public TemplateVideoListVO list(TemplateVideoListDTO templateVideoListDTO) throws XbbException {
        try {
            //获取视频列表
            Map<String, Object> videoMap = new HashMap<>(4);
            videoMap.put("type", templateVideoListDTO.getType());
            videoMap.put("del", DelEnum.NORMAL.getDel());
            videoMap.put("orderByStrGroup", RaidersConstant.ORDER_BY_STR_LIST);
            videoMap.put("columns", "id, name, instruction, img, url, sort");
            List<VideoEntity> videoList = videoModel.findEntitys(videoMap);
            //复制要返回数据
            List<VideoPojo> videoPojoList = new ArrayList<>();
            BeanUtil.copyPropertiesList(videoList, videoPojoList, VideoPojo.class);
            return new TemplateVideoListVO(videoPojoList);
        } catch (XbbException e) {
            throw e;
        } catch (Exception e) {
            LOG.error("获取模板中心视频列表报错", e);
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, SystemErrorCodeEnum.API_ERROR_100001.getMsg());
        }
    }
}
